package com.iemes.controller.transport;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.TransportMaintainFormMap;
import com.iemes.mapper.transport.TransportMaintainMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;

@RequestMapping("/transportMaintain/")
@Controller
public class TransportMaintainController extends BaseController{
	@Inject
	private TransportMaintainMapper transportMaintainMapper;
	//车辆维修申请
		@RequestMapping("/examinetransportMaintain")
		public String examineTransport(Model model){
			model.addAttribute("res", findByRes());
			return Common.BACKGROUND_PATH+"/transport/maintain/transportMaintain_list";
		}
		@ResponseBody
		@RequestMapping("/transportMaintain_findbyPage")
		public PageView findByPage(String pageNow, String pageSize) throws Exception 
		{
			TransportMaintainFormMap transportMaintainFormMap=getFormMap(TransportMaintainFormMap.class);
			List<Map<String, Object>> transportMaintainFormMaps = transportMaintainMapper.getAllInfo(transportMaintainFormMap);
			for (Map<String, Object> map : transportMaintainFormMaps) {
				map.put("total", Common.convertSourData(map.get("count").toString())*Common.convertSourData((map.get("price").toString())));
			}
			
			LuogicPaging(pageNow, pageSize, transportMaintainFormMaps);
			return pageView;
		}
		//删除车辆维修申请
		@ResponseBody
		@RequestMapping("transportMaintain_deleteEntity")
		@Transactional(readOnly=false)//需要事务操作必须加入此注解
		@SystemLog(module="删除车辆维修申请",methods="pod按钮-删除pod按钮")//凡需要处理业务逻辑的.都需要记录操作日志
		public String deleteEntity() throws Exception {
			TransportMaintainFormMap transportMaintainFormMap=getFormMap(TransportMaintainFormMap.class);
			String[] ids = getParaValues("ids");
			String arr=ids[0];
			String[] str=arr.split(",");
			for(int i=0;i<str.length;i++){
				transportMaintainFormMap.set("status", 2);
				transportMaintainFormMap.put("id", str[i]);
				transportMaintainMapper.editEntity(transportMaintainFormMap);
			}
			
			return "success";
		}
}
